#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
验证默认账户配置是否正确
"""
import os
import sys
import json

# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))


class SimpleLogger:
    """简单的日志类"""
    @staticmethod
    def info(msg):
        print(f"INFO: {msg}")
    
    @staticmethod
    def success(msg):
        print(f"SUCCESS: {msg}")
    
    @staticmethod
    def error(msg):
        print(f"ERROR: {msg}")


logger = SimpleLogger()


def verify_default_account():
    """验证默认账户配置是否正确"""
    logger.info("=== 开始验证默认账户配置 ===")
    
    # 路径到账户配置文件
    config_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'config', 'accounts_config.json')
    
    # 检查配置文件是否存在
    if not os.path.exists(config_path):
        logger.error(f"配置文件不存在: {config_path}")
        return False
    
    # 读取配置文件
    try:
        with open(config_path, 'r', encoding='utf-8') as f:
            config = json.load(f)
        logger.info(f"成功读取配置文件: {config_path}")
    except Exception as e:
        logger.error(f"读取配置文件失败: {str(e)}")
        return False
    
    # 检查默认账户是否存在
    accounts = config.get('accounts', {})
    if 'default' not in accounts:
        logger.error("默认账户不存在")
        return False
    
    # 检查默认账户信息是否完整
    default_account = accounts['default']
    required_fields = ['account_id', 'platform', 'account_name', 'description']
    missing_fields = []
    
    for field in required_fields:
        if field not in default_account:
            missing_fields.append(field)
    
    if missing_fields:
        logger.error(f"默认账户缺少字段: {', '.join(missing_fields)}")
        return False
    
    # 检查默认账户是否是活跃账户
    active_account_id = config.get('active_account_id')
    if active_account_id != 'default':
        logger.error(f"默认账户不是活跃账户，当前活跃账户ID: {active_account_id}")
        return False
    
    # 显示默认账户信息
    logger.info("默认账户信息:")
    logger.info(f"  账户ID: {default_account.get('account_id')}")
    logger.info(f"  平台: {default_account.get('platform')}")
    logger.info(f"  账户名称: {default_account.get('account_name')}")
    logger.info(f"  描述: {default_account.get('description')}")
    logger.info(f"  是活跃账户: {'是' if active_account_id == 'default' else '否'}")
    
    # 检查演示凭证文件是否存在
    credentials_path = os.path.join(os.path.dirname(config_path), 'api_credentials.json')
    if os.path.exists(credentials_path):
        logger.success(f"演示凭证文件存在: {credentials_path}")
    else:
        logger.warning(f"演示凭证文件不存在: {credentials_path}")
    
    logger.success("=== 默认账户配置验证通过 ===")
    logger.success("默认账户应该能够在应用界面上正确显示")
    return True


if __name__ == "__main__":
    verify_default_account()